class ControlPanel:
    def __init__(self, set_password):
        self.set_password = set_password  # 预设的密码
        self.input_password = ""  # 当前输入的密码
        self.attempt_count = 0  # 尝试次数
        self.locked = False  # 是否锁定
        self.lock_time = 0  # 锁定时间

    def input_character(self, char):
        if self.locked and time.time() - self.lock_time <= 120:
            print("控制面板已锁定，请稍后再试。")
            return

        self.input_password += char
        print(f"当前输入: {self.input_password[-4:]}")  # 仅显示最后4个字符

        if len(self.input_password) == 4:
            if self.verify_password():
                print("密码正确，进入系统功能选择状态。")
                self.reset_panel()
            else:
                self.handle_wrong_password()

    def verify_password(self):
        return self.input_password[-4:] == self.set_password

    def handle_wrong_password(self):
        self.attempt_count += 1
        print(f"密码错误，您还有{3 - self.attempt_count}次机会。")
        if self.attempt_count >= 3:
            self.lock_panel()
        else:
            self.reset_input()

    def lock_panel(self):
        self.locked = True
        self.lock_time = time.time()
        print("控制面板已锁定，120秒后解锁。")

    def reset_panel(self):
        self.input_password = ""
        self.attempt_count = 0
        self.locked = False
        self.lock_time = 0

    def reset_input(self):
        self.input_password = self.input_password[:-1]  # 删除最后一个字符

# 示例使用
import time
import threading

# 预设密码为1234
control_panel = ControlPanel("1234")

# 模拟用户输入
def simulate_user_input():
    # 示例输入：错误密码，然后正确密码
    inputs = ['1', '2', '5', '6',  # 第一次尝试错误
              '1', '2', '3', '5',  # 第二次尝试错误
              '1', '2', '3', '4',  # 第三次尝试正确
              'a', 'b', 'c', 'd']  # 锁定后尝试

    for char in inputs:
        threading.Timer(1, control_panel.input_character, [char]).start()  # 模拟按键延迟

simulate_user_input()